<?php

namespace common\models\qywx;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\qywx\QywxApp;

/**
 * QywxAppSearch represents the model behind the search form about `common\models\qywx\QywxApp`.
 */
class QywxAppSearch extends QywxApp
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['qywx_app_id'], 'integer'],
            [['qywx_app_name', 'qywx_app_corp_id', 'qywx_app_corp_secret', 'qywx_app_memo', 'qywx_app_created_by', 'qywx_app_created_at', 'qywx_app_updated_by', 'qywx_app_updated_at'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = QywxApp::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'qywx_app_id' => $this->qywx_app_id,
            'qywx_app_created_at' => $this->qywx_app_created_at,
            'qywx_app_updated_at' => $this->qywx_app_updated_at,
        ]);

        $query->andFilterWhere(['like', 'qywx_app_name', $this->qywx_app_name])
            ->andFilterWhere(['like', 'qywx_app_corp_id', $this->qywx_app_corp_id])
            ->andFilterWhere(['like', 'qywx_app_corp_secret', $this->qywx_app_corp_secret])
            ->andFilterWhere(['like', 'qywx_app_memo', $this->qywx_app_memo])
            ->andFilterWhere(['like', 'qywx_app_created_by', $this->qywx_app_created_by])
            ->andFilterWhere(['like', 'qywx_app_updated_by', $this->qywx_app_updated_by]);

        return $dataProvider;
    }
}
